package com.browser.security;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.HashMap;
import java.util.Map;

public class PermissionManager {
    private static final Logger logger = LoggerFactory.getLogger(PermissionManager.class);
    private final Map<String, Map<Permission, Boolean>> permissions;

    public PermissionManager() {
        this.permissions = new HashMap<>();
    }

    public boolean hasPermission(String domain, Permission permission) {
        Map<Permission, Boolean> domainPermissions = permissions.get(domain);
        if (domainPermissions != null) {
            Boolean permitted = domainPermissions.get(permission);
            return permitted != null && permitted;
        }
        return false;
    }

    public void grantPermission(String domain, Permission permission) {
        logger.debug("Granting permission {} for domain: {}", permission, domain);
        permissions.computeIfAbsent(domain, k -> new HashMap<>())
                  .put(permission, true);
    }

    public void revokePermission(String domain, Permission permission) {
        logger.debug("Revoking permission {} for domain: {}", permission, domain);
        Map<Permission, Boolean> domainPermissions = permissions.get(domain);
        if (domainPermissions != null) {
            domainPermissions.put(permission, false);
        }
    }

    public enum Permission {
        GEOLOCATION,
        NOTIFICATIONS,
        CAMERA,
        MICROPHONE,
        CLIPBOARD,
        STORAGE
    }
} 